/**
* @file:Ctypes.cpp
* This file contains class Ctypes which is used as an interface between ANTLR and C++. All the rules set in ANTLR are called from here
* @author: Elie Shaccour (elie.shaccour@gmail.com)
*
*
*/

#include <string>
#include <iostream>

#include "C_typesParser.h"
#include "C_typesLexer.h"
#include "antlradapter.h"

using namespace std;

AntlrAdapter::AntlrAdapter()
{
}

void AntlrAdapter::Set()
{
input = antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)UserInput.c_str(),UserInput.size(),NULL);
lex    = C_typesLexerNew                (input);
tokens = antlr3CommonTokenStreamSourceNew  (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));
parser = C_typesParserNew               (tokens);
}

string AntlrAdapter::Def(string Line)
{
///set input in the class to 'line
UserInput=Line;
///set up parameters
Set();
///get output
Output=parser->def(parser);
///clean the allocated data
Clean();
///return output
return Output;
}


string AntlrAdapter::Use(string Line)
{
UserInput=Line;
Set();
Output=parser->use(parser);
Clean();
return Output;
}

void AntlrAdapter::Clean()
{
parser ->free(parser);
tokens ->free(tokens);
lex    ->free(lex);
input  ->close(input);
}

vector<int> *AntlrAdapter::TestCriteriaParameters(string Line)
{
UserInput=Line;
Set();
vector<int> *v=(parser->testcriteria(parser));
Clean();
return v;
}
/*
int Ctypes::linescope(string line)
{
LR_input=line;
set();
int v=(parser->linescope(parser));
clean();
return v;
}

string Ctypes::functionname(string line)
{
LR_input=line;
set();
string v=(parser->functionname(parser));
clean();
return v;
}


string Ctypes::description(string line)
{
LR_input=line;
set();
string v=(parser->description(parser));
clean();
return v;
}

vector<string>* Ctypes::path(string line)
{
LR_input=line;
set();
vector<string> *v=(parser->path(parser));
clean();
return v;
}
*/

AntlrAdapter::~AntlrAdapter()
{
}
